package com.adtech.adms.mainview.web.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.adtech.adms.SessionKey;
import com.adtech.adms.system.pojo.User;
import com.adtech.adms.system.service.UserService;
import com.adtech.core.web.action.BaseAction;

/**
 * 注销类
 * 用户注销
 * @author Dormin 
 * @since 2011-6-3 
 * 
 * @Copyright (C) AD Tech Workshop All Right Reserved
 */
public class LogoutAction extends BaseAction implements ServletRequestAware {
	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(LogoutAction.class);
	private UserService userService;

	private HttpServletRequest httpRequest;

	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

//	public SystemLogService getSystemLogService() {
//		return systemLogService;
//	}
//	public void setSystemLogService(SystemLogService systemLogService) {
//		this.systemLogService = systemLogService;
//	}
	@Override
	public String execute() {
		User user = (User) httpRequest.getSession().getAttribute(SessionKey.SESSION_KEY_USER);
		if(user!=null) {
			user.setIsLogout("1");
		}
		try {
			httpRequest.getSession().invalidate();
		} catch(Exception e) {
			log.error(e);
		}
		return SUCCESS;
	}
	
	public void setServletRequest(HttpServletRequest request) {
		this.httpRequest = request;
	}
}
